package com.socket.TCP;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.URL;
import java.util.Arrays;

/**
 * Created by wangyg on 2016/10/31.
 */
public class TestSocket {
	public static void main(String[] args) throws IOException {
		InetAddress address = InetAddress.getLocalHost();
		System.out.println("计算机名：" + address.getHostName());
		System.out.println("IP地址：" + address.getHostAddress());
		byte[] addressList = address.getAddress();
		System.out.println("字节数组形式的ip：[" + Arrays.toString(addressList));
		System.out.println(address);

		URL url = new URL("http://www.baidu.com");
		System.out.println(url.getProtocol());
		InputStream is = url.openStream();
		InputStreamReader isr = new InputStreamReader(is);
		BufferedReader br = new BufferedReader(isr);
		String s = br.readLine();
		while (s != null) {
			System.out.println(s);
			s = br.readLine();
		}
		br.close();
		isr.close();
		is.close();
	}
}
